package cn.agiledata.bank.linkbank.impl.ccb;

import java.util.Date;

import cn.agiledata.bank.account.service.ISequenceGenerator;
import cn.agiledata.bank.linkbank.logic.OrderIdTransformer;

/**
 * 中国建设银行外卡支付订单编号转换器。提供支付系统交易编号与向建设银行外卡支付提交的订单编号的转换逻辑
 * 
 * @author 马贤波
 * 
 */
public final class CcbIntlOrderIdTransformer implements OrderIdTransformer {
	private Date date;

	private ISequenceGenerator sequenceGenerator;

	public void setSequenceGenerator(ISequenceGenerator sequenceGenerator) {
		this.sequenceGenerator = sequenceGenerator;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String orderId2TransId(String orderId) {
		if (orderId == null)
			return null;
		return this.sequenceGenerator
				.getTransactionSequence(this.date, orderId);
	}

	public String transId2OrderId(String transId) {
		if (transId == null || transId.length() < 6)
			return null;
		return transId.substring(transId.length() - 6);
	}
}
